package com.keyinong.caizhengting.customdatapicker;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Typeface;

public class MSurface {
    public float density;
    public int width;// 整个控件的宽度
    public int height;// 整个控件的高度
    public float monthHeight;// 显示月的高度
    public float weekHeight; // 显示星期的高度
    public float cellWidth; // 日期方框宽度
    public float cellHeight; // 日期方框高度
    public float borderWidth;
    public int bgColor = Color.parseColor("#FFFFFF");
    public int textColor = Color.BLACK;
    public int btnColor = Color.parseColor("#666666");
    public int borderColor = Color.parseColor("#CCCCCC");
    public int todayNumberColor = Color.RED;
    public int cellDownColor = Color.parseColor("#CCFFFF");
    public int cellSelectedColor = Color.parseColor("#99CCFF");
    public Paint borderPaint;
    public Paint monthPaint;
    public Paint weekPaint;
    public Paint datePaint;
    public Paint monthChangeBtnPaint;
    public Paint cellBgPaint;
    public Path boxPath; // 边框路径
    public String weekText[] = {"7", "1", "2", "3", "4", "5", "6"};
    public String[] monthText = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

    public void init() {
        float temp = height / 7f;
        monthHeight = 0; // (float) ((temp + temp * 0.3f) * 0.6);
        // monthChangeWidth = monthHeight * 1.5f;
        weekHeight = (float) ((temp + temp * 0.3f) * 0.7);
        // cellHeight =(height - monthHeight - weekHeight) / 6f; ;
        cellWidth = width / 7f;
        borderPaint = new Paint();
        borderPaint.setColor(borderColor);
        borderPaint.setStyle(Paint.Style.STROKE);
        borderWidth = (float) (0.5 * density);

        borderWidth = borderWidth < 1 ? 1 : borderWidth;
        borderPaint.setStrokeWidth(borderWidth);

        monthPaint = new Paint();
        monthPaint.setColor(textColor);
        monthPaint.setAntiAlias(true);
        float textSize = cellHeight * 0.4f;
        monthPaint.setTextSize(textSize);
        monthPaint.setTypeface(Typeface.DEFAULT_BOLD);
        weekPaint = new Paint();
        weekPaint.setColor(textColor);
        weekPaint.setAntiAlias(true);
        float weekTextSize = weekHeight * 0.6f;
        weekPaint.setTextSize(weekTextSize);
        weekPaint.setTypeface(Typeface.DEFAULT_BOLD);

        datePaint = new Paint();
        datePaint.setColor(textColor);
        datePaint.setAntiAlias(true);
        float cellTextSize = cellHeight * 0.5f;
        datePaint.setTextSize(cellTextSize);
        datePaint.setTypeface(Typeface.DEFAULT_BOLD);

        boxPath = new Path();
        boxPath.rLineTo(width, 0);
        boxPath.moveTo(0, monthHeight + weekHeight);
        boxPath.rLineTo(width, 0);
        for (int i = 1; i < 6; i++) {
            boxPath.moveTo(0, monthHeight + weekHeight + i * cellHeight);
            boxPath.rLineTo(width, 0);
            boxPath.moveTo(i * cellWidth, monthHeight);
            boxPath.rLineTo(0, height - monthHeight);
        }
        boxPath.moveTo(6 * cellWidth, monthHeight);
        boxPath.rLineTo(0, height - monthHeight);

        monthChangeBtnPaint = new Paint();
        monthChangeBtnPaint.setAntiAlias(true);
        monthChangeBtnPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        monthChangeBtnPaint.setColor(btnColor);

        cellBgPaint = new Paint();
        cellBgPaint.setAntiAlias(true);
        cellBgPaint.setStyle(Paint.Style.FILL);
        cellBgPaint.setColor(cellSelectedColor);

    }
}
